package com.jlnk.stockdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.jlnk.stockdemo.R;
import com.jlnk.stockdemo.bean.ForexListResponse;

import java.util.List;

public class ForexAdapter extends RecyclerView.Adapter<ForexAdapter.ForexViewHolder> {
    private List<ForexListResponse.Data.Forex> forexItems;

    public ForexAdapter(List<ForexListResponse.Data.Forex> forexItems) {
        this.forexItems = forexItems;
    }

    @Override
    public ForexViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_forex_list, parent, false);
        return new ForexViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ForexViewHolder holder, int position) {
        ForexListResponse.Data.Forex forexItem = forexItems.get(position);
        holder.tv_name.setText((String) forexItem.getName());
        holder.tv_classify.setText((String) forexItem.getClassify());
        holder.tv_exchange.setText((String) forexItem.getExchange());
        holder.tv_pip_cost.setText((String) forexItem.getPip_cost());
        holder.tv_traget_spread.setText((String) forexItem.getTraget_spread());

    }

    @Override
    public int getItemCount() {
        return forexItems.size();
    }

    public static class ForexViewHolder extends RecyclerView.ViewHolder {
        TextView tv_name;
        TextView tv_classify;
        TextView tv_exchange;
        TextView tv_pip_cost;
        TextView tv_traget_spread;

        public ForexViewHolder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_classify = itemView.findViewById(R.id.tv_classify);
            tv_exchange = itemView.findViewById(R.id.tv_exchange);
            tv_pip_cost = itemView.findViewById(R.id.tv_pip_cost);
            tv_traget_spread = itemView.findViewById(R.id.tv_traget_spread);
        }
    }
}
